package com.qf.utils;

import com.qiniu.storage.Configuration;
import com.qiniu.storage.Region;
import com.qiniu.storage.UploadManager;
import com.qiniu.util.Auth;
import org.springframework.beans.factory.annotation.Value;

/**
 * Created by 54110 on 2021/1/12.
 */

public class UploadToken {
    public static String upload(){

        //构造一个带指定 Region 对象的配置类
        Configuration cfg = new Configuration(Region.region1());
//...其他参数参考类注释
        UploadManager uploadManager = new UploadManager(cfg);
//...生成上传凭证，然后准备上传
        String accessKey = "a-OClLtMqZilZNhY3AVbwiOjfX70Boa7ZGRv4rhz";
        String secretKey = "QoW3nnBLpXdA-inXAQ1R3ThKKpTs32rO0IgJNHhf";
        String bucket = "takeout";
        //默认不指定key的情况下，以文件内容的hash值作为文件名
        String key = null;
            //byte[] bytes = multipartFile.getBytes();
            //ByteArrayInputStream byteInputStream=new ByteArrayInputStream(bytes);
            Auth auth = Auth.create(accessKey, secretKey);
            String upToken = auth.uploadToken(bucket);
            System.out.println(upToken);
            return upToken;
    }

}

